package org.bulldog.playlist.message;

import org.bulldog.playlist.util.DateUtil;

/**
 * Created by zhanghongbin on 2017/9/13.
 *
 * @author zhanghongbin
 * @version 1.0
 */
public final class Message {

    public static enum Code {
        //节目
        EXIT(-1), PROGRAM(0), OTHER(1);
        int code;

        Code(int code) {
            this.code = code;
        }
    }

    private Enum code;

    private String id = "";


    private String content = "";

    private int playDuration = 0;
    private String startTime = "";
    private String endTime = "";

    private int duration = 0;

    public String getId() {
        return id;
    }

    public int getPlayDuration() {
        return playDuration;
    }

    public String getContent() {
        return content;
    }

    public Enum getCode() {
        return code;
    }

    public Message(Enum code, String id, int playDuration) {
        this.code = code;
        this.id = id;
        this.playDuration = playDuration;
        this.startTime = DateUtil.now();
        this.endTime = DateUtil.add(this.startTime, playDuration);
        this.duration = playDuration;
    }

    void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    void setPlayDuration(int playDuration) {
        this.playDuration = playDuration;
    }

    public String getStartTime() {
        return startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public int getDuration() {
        return duration;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("{\"code\":" + code.ordinal() + ",").
                append("\"id\":" + "\"" + this.id + "\",").append("\"content\":\"" + this.content + "\",")
                .append("\"startTime\":\"" + this.startTime + "\",").append("\"endTime\":\"" + this.endTime + "\",")
                .append("\"duration\":" + this.duration + ",").append("\"playDuration\":" + this.playDuration + "}");
        return stringBuilder.toString();
    }

}
